< previous page page_406 next page >

Page 406
9f31265bb40b592b1929e18a47ab28e5.gif
         If .OpenTextFile(strFileName, ForReading) Then
            Do Until .AtEndOfStream
               strValue = strValue & .ReadLine & vbCrLf
            Loop
            .CloseFile
            txtEdit.Text = strValue
         End If
      End If
   End With
   Set oFile = Nothing

   Screen.MousePointer = vbDefault
End Sub
After declaring a TextStream object, you first get the filename from a function called GetFileName(). This is a general function that retrieves the path and filename from the directory and file list box controls. Next, you fill in the FileName property of the TextStream object so you can call the FileTooBig property. This property returns True if the file is larger than 32KB.
Next, you open the file by passing the filename and the constant ForReading to the OpenTextFile() method. If the file is opened correctly, you can loop through it until you hit the end of the input stream. Each time through the loop, youll invoke the ReadLine() method to return the line of information just read. Notice that you concatenate onto each line a CRLF. This is because the ReadLine method does not read the CRLF pair.
The FileTooBig Property
Prior to reading in the data from the file, you should first check to see whether the file is small enough to be put into a text file. In the cmdRead_Click() event, the FileTooBig property is queried to see whether the file chosen can fit into a text box. Assuming a text box is limited to 32KB, you can create the FileTooBig property as follows:
9f31265bb40b592b1929e18a47ab28e5.gif
Property Get FileTooBig() As Boolean
   If FileLen(mstrFileName) > 32768 Then
      FileTooBig = True
   Else
      FileTooBig = False
   End If
End Property

 
< previous page page_406 next page >

If you like this book, buy it!